package com.hkts.naturalgas.workshop.service.serviceimpl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hkts.naturalgas.workshop.entity.HktsWorkShop;
import com.hkts.naturalgas.workshop.mapper.HktsWorkShopMapper;
import com.hkts.naturalgas.workshop.service.IHktsWorkShopService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author yck
 * @since 2021-10-08
 */
@Service
@Transactional
public class HktsWorkShopServiceImpl extends ServiceImpl<HktsWorkShopMapper, HktsWorkShop> implements IHktsWorkShopService {


    @Autowired
    private HktsWorkShopMapper hktsWorkShopMapper;

    @Override
    public IPage<HktsWorkShop> selectPage(Page<HktsWorkShop> page, HktsWorkShop hktsWorkShop) {
        QueryWrapper<HktsWorkShop> query = Wrappers.query();
        QueryWrapper<HktsWorkShop> entityWrapper = getEntityWrapper(query, hktsWorkShop);
        return hktsWorkShopMapper.selectPage(page, entityWrapper);
    }


    @Override
    public List<HktsWorkShop> selectList(HktsWorkShop hktsWorkShop) {
        QueryWrapper<HktsWorkShop> query = Wrappers.query();
        QueryWrapper<HktsWorkShop> entityWrapper = getEntityWrapper(query, hktsWorkShop);
        return hktsWorkShopMapper.selectList(entityWrapper);
    }

    /**
     * 公共查询条件
     *
     * @param entityWrapper
     * @return
     */
    public QueryWrapper<HktsWorkShop> getEntityWrapper(QueryWrapper<HktsWorkShop> entityWrapper, HktsWorkShop hktsWorkShop) {

        return entityWrapper;
    }

    @Override
    public HktsWorkShop getWorkShopByCode(String code) {
        QueryWrapper<HktsWorkShop> query = Wrappers.query();
         query.lambda().eq(HktsWorkShop::getWorkShopCode, code);
        return hktsWorkShopMapper.selectOne(query);
    }

    @Override
    public HktsWorkShop checkForExist(HktsWorkShop hktsWorkShop) {
        QueryWrapper<HktsWorkShop> query = Wrappers.query();
        query.lambda().eq(HktsWorkShop::getWorkShopName,hktsWorkShop.getWorkShopName());
      // query.lambda().eq(HktsWorkShop::getPassWord,hktsWorkShop.getPassWord());
        HktsWorkShop hktsWorkShop1 = hktsWorkShopMapper.selectOne(query);

        return hktsWorkShop1;
    }
}
